package recursion.leetcode.editor.cn;


public class PowerOfThree {
    public static void main(String[] args) {
        Solution solution = new PowerOfThree().new Solution();
        System.out.println(solution.isPowerOfThree(27));
        System.out.println(solution.isPowerOfThree(0));
        System.out.println(solution.isPowerOfThree(9));
        System.out.println(solution.isPowerOfThree(45));
        System.out.println(solution.isPowerOfThree(2));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean isPowerOfThree(int n) {
            if (n == 1) {
                return true;
            } else {
                if (n ==0||n % 3 != 0 ) {
                    return false;
                } else {
                    return isPowerOfThree(n / 3);
                }
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}